The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.

Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.

(Please note that the palindromic number, in either base, may not include leading zeros.)


In [33]:
let toBinary (n:int) = 
    System.Convert.ToString(n, 2)
    
let strRev (s:string) = new string(Array.rev (s.ToCharArray()))

let isPalindrome (s:string) =
    s = (strRev s)
    
let bothBasePalindrome n = 
    (isPalindrome (string(n))) && (isPalindrome (toBinary n))
    
[0..1000000]
|> List.filter bothBasePalindrome
|> List.sum


Out[33]:
872187